﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Baimasoft.Manage.SqlServerDAL;

public partial class SysManage_MenuTree_Right : System.Web.UI.Page
{
    public DataSet myds;
    public DataView mydv;
   
    MenuManage MyMM = new MenuManage();

    protected void Page_Load(object sender, EventArgs e)
    {
        if ((string)Session["Baimasoft_User_LogonID"] == null)
        {
            Response.Redirect("../ReLogon.aspx");
        }
        if (!Page.IsPostBack)
        {
            PageBind();            
        }
        SaveTreeInfo();
    }

    //页面下拉数据项绑定
    private void PageBind()
    {
        homologID.DataSource = MyMM.GetPageInfo();
        homologID.DataBind();
        //			homologID.Items.Insert(0,"请选择");
    }

    //private void SysCateGoryDrop()
    //{
    //    SysCateGory.DataSource = MyUM.BackView(21,"");
    //    SysCateGory.DataBind();
    //}

    public void SaveTreeInfo()
    {
        string sMod = hidMod.Value;
        string sHidCode = hidCode.Value;
        string sCode = code.Value;
        string sType = null;
        string iHomologID = "0";
        string sLabel = label.Value;

        //取被选中的结点类型

        if (List.Checked == true)
        {
            sType = List.Value;
        }
        else
        {
            sType = CPage.Value;
        }

        if (sType.Equals("0"))
        {
            iHomologID = homologID.Value;
        }

        //string sql = "";
        try
        {
            if (sMod.Equals("ADD"))
            {
                //sql = "insert Sys_Menu_Tree(Code,Type,Page_ID,Label) values('" + sCode + "','" + sType + "','" + iHomologID + "','" + sLabel + "')";
                //mycomm = new SqlCommand(sql, MyDataConn .Connection );
                //mycomm.ExecuteNonQuery();
                MyMM.AddNoteCode(sCode, sType, iHomologID, sLabel);
            }

            if (sMod.Equals("INS") || sMod.Equals("APD"))
            {
                //sql = "sys_InsCtlNode '" + sCode + "','" + sType + "','" + iHomologID + "','" + sLabel + "'";
                //mycomm = new SqlCommand(sql, MyDataConn.Connection );
                //mycomm.ExecuteNonQuery();
                MyMM.InsertNoteCode(sCode, sType, iHomologID, sLabel);
            }

            if (sMod.Equals("ALT"))
            {
                string sOriginalType = hidType.Value;
                string iOriginalHomologID = hidHomologID.Value;
                string sLeafed = hidLeafed.Value;
                //sql = "update Sys_Menu_Tree set Type='" + sType + "',Page_ID='" + iHomologID + "',Label='" + sLabel + "' where Code='" + sCode + "'";
                //mycomm = new SqlCommand(sql, MyDataConn.Connection );
                //mycomm.ExecuteNonQuery();
                MyMM.UpdateNoteCode(sCode, sType, iHomologID, sLabel);
            }

            if (sMod.Equals("DEL"))
            {
                //sql = "sys_DelCtrlNode '" + sHidCode + "'";
                //mycomm = new SqlCommand(sql, MyDataConn.Connection );
                //mycomm.ExecuteNonQuery();
                MyMM.DeleteNoteCode(sHidCode);
            }
        }
        catch
        {
        }
        
        //label1.Text="<table width=90% border=1 cellpadding =1 cellspacing =1><tr><td align=right width=60%>添加子结点(ADD),前插(INS)<br>后插(APD),修改(ALT),删除(DEL)</td><td><font color=red>"+sMod+"</font></td></tr><tr><td align=right>结点编码</td><td><font color=red>"+sHidCode+"</font></td></tr><tr><td align=right>新结点编码</td><td><font color=red>"+sCode+"</font></td></tr><tr><td align=right>结点类型,目录(2)页面(1)</td><td><font color=red>"+sType+"</font></td></tr><tr><td align=right>对应控件0表示没有对应元件</td><td><font color=red>"+iHomologID+"</font></td></tr><tr><td align=right>结点标签</td><td><font color=red>"+sLabel+"</font></td></tr></table>";
    }
}
